//
// by Jan Eric Kyprianidis <www.kyprianidis.com>
// Copyright (C) 2010-2012 Computer Graphics Systems Group at the
// Hasso-Plattner-Institut, Potsdam, Germany <www.hpi3d.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
#include <oz/gpu_timer.h>


oz::gpu_timer::gpu_timer() {
    cudaEventCreate(&m_start);
    cudaEventCreate(&m_stop);
    cudaEventRecord(m_start, 0);
}


oz::gpu_timer::~gpu_timer() {
    cudaEventDestroy(m_start);
    cudaEventDestroy(m_stop);
}


void oz::gpu_timer::reset() {
    cudaEventRecord(m_start, 0);
}


double oz::gpu_timer::elapsed_time( bool reset ) {
    cudaEventRecord(m_stop, 0);
    cudaEventSynchronize(m_stop);
    float elapsedTime;
    cudaEventElapsedTime(&elapsedTime, m_start, m_stop);
    if (reset) cudaEventRecord(m_start, 0);
    return elapsedTime;
}
